Skip to main content

Create a Repository

1. What is a Repository

  • You can simply think of it as a directory. All files in this directory can be managed by Git.
  • Git can track the modification and deletion of each file, so that the history can be tracked at any time, or it can be "restored" at some point.
$ mkdir learngit
$ cd learngit
$ pwd

pwd The command is used to display the current directory. This repository is located at /Users/ASUS/Documents/learngit.

screenshot

git is to turn this directory into a repository that can be managed by Git through the command:

$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/

$ ls -ah

screenshot

You can find that there is an extra .git directory under the current directory. This directory is used by Git to track and manage the version library. Do not manually modify the files in this directory, otherwise the Git repository will be destroyed if you make a mess of them.

If you don't see .git the directory, it's because the directory is hidden by default. ls -ah You can see it using the command.

screenshot

screenshot

2. Add files to the Repo

$ git add <file>
$ git commit -m <message>

screenshot